package org.realogic.cfm.domain;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class KList<E> implements List<E> {

	private List<E> datas;

	private int pageNo = 0;

	private int pageSize = 0;

	private int totalSize = 0;


	public KList() {
		this.datas = new ArrayList<E>();
	}

	public KList(int initialCapacity) {
		this.datas = new ArrayList<E>(initialCapacity);
	}
	
	public KList(List<E> datas) {
		this.datas = datas;
	}

	public KList(int totalSize, int pageNo, int pageSize) {
		if (pageSize > 0) {
			this.datas = new ArrayList<E>(pageSize);
		} else {
			this.datas = new ArrayList<E>();
		}
		this.pageNo = pageNo;
		this.pageSize = pageSize;
		this.totalSize = totalSize;
	}
	
	public KList(List<E>  datas,int totalSize, int pageNo, int pageSize) {
		this.datas = datas;
		this.pageNo = pageNo;
		this.pageSize = pageSize;
		this.totalSize = totalSize;
	}

	public List<E> getDatas() {
		return datas;
	}

	public boolean isDisplayByPage() {
		return pageNo > 0 && pageSize > 0;
	}

	public int getPageNo() {
		return pageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public int getPageCount() {
		return 1 + (totalSize - 1) / getPageSize();
	}

	public int getStartIndex() {
		return (getPageNo() - 1) * getPageSize() + 1;
	}

	public int getEndIndex() {
		return getStartIndex() + size() - 1;
	}

	public int getTotalSize() {
		return totalSize;
	}

	@Override
	public int size() {
		return datas.size();
	}

	@Override
	public boolean isEmpty() {
		return datas.isEmpty();
	}

	@Override
	public boolean contains(Object o) {
		return datas.contains(o);
	}

	@Override
	public Iterator<E> iterator() {
		return datas.iterator();
	}

	@Override
	public Object[] toArray() {
		return datas.toArray();
	}

	@Override
	public <T> T[] toArray(T[] a) {
		return datas.toArray(a);
	}

	@Override
	public boolean add(E e) {
		return datas.add(e);
	}

	@Override
	public boolean remove(Object o) {
		return datas.remove(o);
	}

	@Override
	public boolean containsAll(Collection<?> c) {
		return datas.contains(c);
	}

	@Override
	public boolean addAll(Collection<? extends E> c) {

		return datas.addAll(c);
	}

	@Override
	public boolean addAll(int index, Collection<? extends E> c) {

		return datas.addAll(index, c);
	}

	@Override
	public boolean removeAll(Collection<?> c) {

		return datas.removeAll(c);
	}

	@Override
	public boolean retainAll(Collection<?> c) {

		return datas.retainAll(c);
	}

	@Override
	public void clear() {
		datas.clear();
		datas = null;

	}

	@Override
	public E get(int index) {
		return datas.get(index);
	}

	@Override
	public E set(int index, E element) {

		return datas.set(index, element);
	}

	@Override
	public void add(int index, E element) {
		datas.add(index, element);
	}

	@Override
	public E remove(int index) {
		return datas.remove(index);
	}

	@Override
	public int indexOf(Object o) {
		return datas.indexOf(o);
	}

	@Override
	public int lastIndexOf(Object o) {
		return datas.lastIndexOf(o);
	}

	@Override
	public ListIterator<E> listIterator() {
		return datas.listIterator();
	}

	@Override
	public ListIterator<E> listIterator(int index) {
		return datas.listIterator(index);
	}

	@Override
	public List<E> subList(int fromIndex, int toIndex) {
		return datas.subList(fromIndex, toIndex);
	}

}